<template>
        <h2>登录</h2>
<table>
    <tr>
        <td>用户名</td>
        <td>
            <input type="text" v-model="info.name">
        </td>
    </tr>
    <tr>
        <td>密码</td>
        <td>
            <input type="password" v-model="info.pwd" >
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <button @click="login">登录</button>
        </td>
    </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from "vue"
import axios from "axios"
import { useRouter } from "vue-router"

const router = useRouter()

const info = ref({
    name: "",
    pwd: "",
})

const login = () => {
    axios.get("http://localhost:53393/api/User/Login", {
        params:{
            name: info.value.name,
            pwd: info.value.pwd
        }

    }).then(res => {
        if (res.data.Lid==1)
         {
            alert(res.data.Lname)
            UserPd(res.data.Ldata[0].Uid)
            
        } 
        else if(res.data.Lid==-1)
        {
            alert(res.data.Lname)
        }
        else if(res.data.Lid==-2)
        {
            alert(res.data.Lname)
        }
        else
        {
            alert("登录失败")
        }
    })
}

const UserPd = (Uid:string) => {
    axios.get("http://localhost:53393/api/User/UserPd", {
        params:{
            Uid:Uid,
        }

    }).then(res => {
        if(res.data>0)
        {
            alert("进入显示页面")
        }
        else
        {
            router.push({
                path: "/Userlog",
                query: {
                    Uid: Uid,
                }
            })
        }
    })

    .catch(err => {
        console.log(err);
    })
}
</script>
